package com.jadows.tdog.message;

import com.jadows.tdog.constants.GlobalConstants;
import lombok.AllArgsConstructor;
import lombok.Data;

import static com.jadows.tdog.constants.GlobalActions.RESP_MSG;

@Data
@AllArgsConstructor
public class WSRespWrapper {
    /**
     * ws推送给前端的消息
     */
    private Integer code;
    private String msg;
    private Object data;
    private String seq;
    private String action = RESP_MSG;

    public WSRespWrapper(String seq) {
        this.seq = seq;
    }

    public static WSRespWrapper ok(String seq, Object data) {
        WSRespWrapper wsRespWrapper = new WSRespWrapper(seq);
        wsRespWrapper.setCode(GlobalConstants.SUCCESS);
        wsRespWrapper.setMsg(GlobalConstants.OK);
        wsRespWrapper.setData(data);
        return wsRespWrapper;
    }

    public static WSRespWrapper fail(String seq, Integer code, String msg) {
        WSRespWrapper wsRespWrapper = new WSRespWrapper(seq);
        wsRespWrapper.setCode(code);
        wsRespWrapper.setMsg(msg);
        return wsRespWrapper;
    }
}
